﻿/*
 * User: David
 * Date: 29/06/2013
 * Time: 1:22 AM
 * 
 */
using System;
using System.Collections.Generic;
using HockeySimulator.Interfaces;

namespace HockeySimulator.Entities.League
{
	/// <summary>
	/// Description of League.
	/// </summary>
	public class League:iExportable
	{
		long SalarialCap;
		private string Name;
		private List<Conference> Conferences;
		
		//Constructors
		public League(bool UseDefaultInitialize = false)
		{
			if(UseDefaultInitialize)
				defaultLeagueInitialize();
			else
			{
				Name = "";
				Conferences = new List<Conference>();
			}
		}
		
		public League(List<Conference> ConferenceList, string LeagueName = "")
		{
			Name = (LeagueName!= null?LeagueName:"");
			
			if (ConferenceList.Count > 0)
			{
				Conferences = new List<Conference>(ConferenceList);
			}
			else
			{
				Conferences = new List<Conference>();
			}
		}
		
		private void defaultLeagueInitialize()
		{
			Name = "DefaultLeagueName";
			Conferences = new List<Conference>();
			
			AddConference(new Conference(true));
			AddConference(new Conference(true));
		}
		
		//Interface method
		
		public string Export()
		{
			string NL = Environment.NewLine;
			
			string result = "League : " + Name + NL;
			result += "*************************" + NL;
			
			if (Conferences != null)
			{
				if(Conferences.Count == 0)
					result += "No conferences";
				else
				{
					foreach (Conference C in Conferences)
					{
						result += C.Export() + NL;
						result += "*************************" + NL;
					}
				}
			}
			else
			{
				result += "No conferences";
			}
			
			return result;
		}
		
		//Other methods
		public void AddConference(Conference C)
		{
			//TODO Throw error if null
			if(Conferences != null)
				Conferences.Add(C);
		}
		
		public void ReinitializeConferences()
		{
			Conferences = new List<Conference>();
		}
		
		
	}
}
